﻿#encoding: utf-8
#this file can be used in other ruby file by loading 'wechat_api.rb'

load 'wechat_api.rb'
load 'rds_api.rb'
@rds = @rds_tt

#通过get_wework_corp_tag_list获得标签信息

def mark_billed_tupals
    counter = 0;
    print "mark billed tupals: "
    sql = "select * from tutem_mall.eb_wework_external_contact where unionid in (
        select unionid from tutem_mall.eb_wechat_user where uid in (
            select uid from tutem_mall.eb_user_bill where title like '%TUPAL%'
        )
    );"
    (queryRds(sql)).each do |rec|
        userid = rec['follow_info_userid']
        external_userid = rec['external_userid']
        mark_wework_tag userid, external_userid, ['etgTjVCAAA9Bw08-PtUaPm6YMMwu8gPw'], []
        print ('.')
    end
    puts "#{counter} done" 
end

#给注册过计划的用户打上标签
def mark_enrolled_tupals
    counter = 0;
    print "mark enrolled tupals: "
    sql = " select * from tutem_mall.eb_wework_external_contact where unionid in (
        select unionid from tutem_mall.eb_wechat_user where uid in (
            select uid from tutem_mall.eb_tupal where status != 'PENDING'
        )
    );"
    (queryRds(sql)).each do |rec|
        userid = rec['follow_info_userid']
        external_userid = rec['external_userid']
        mark_wework_tag userid, external_userid, ['etgTjVCAAA9Bw08-PtUaPm6YMMwu8gPw'], []
        counter += 1
        print ('.')
    end
    puts "#{counter} done" 
end

#给领过图腾之友积分的用户打上标签，方便客服群发
def fix_tupal_marks_20240620
    #mark_billed_tupals
    mark_enrolled_tupals
end
#fix_tupal_marks_20240620
